var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
        leixing:1,
		datalist: [],
		pagenum: 1,
	},
	_onLoad:function(){
		var that = this
		if(that.options && that.options.cid){
			that.setData({cid:that.options.cid});
        }
        
        $.get('yuxun/getmycollect', { }, function (res) {
            that.setData(res);
        });
		that.setData({ pagenum: 1, datalist: [], $nomoreData: false });
		that.getDataList();
	},
	getDataList: function () {
		var that = this
		var pagenum = that.data.pagenum
		that.setData({loaddingmore:true})
        $.post('yuxun/getmycollect', { pagenum: pagenum}, function (res) {
			that.setData({loaddingmore:false})
			var data = res.data
			if (pagenum == 1) {
				that.setData({ datalist: data });
				if (data.length == 0) {
					$.showEmpty('暂无相关数据！');
				}
			} else {
				if (data.length == 0) {
					that.setData({ $nomoreData: true });
				} else {
					var datalist = that.data.datalist
					var newdata = datalist.concat(data)
					that.setData({ datalist: newdata });
				}
			}
		},false);
	},
	onReachBottom: function () {
		if (!this.data.$dataEmpty.visible && !this.data.$nomoreData) {
			this.setData({ pagenum: this.data.pagenum + 1 })
			this.getDataList();
		}
    },
    cancelcollect:function(e){
        var id = e.currentTarget.dataset.id;
        $.post('yuxun/cancelcollect', { id: id}, function (res) {
            if(res.status==1){
                var datalist = that.data.datalist;
                datalist.splice(id,1);
                console.log(datalist)
		        that.setData({datalist:datalist});
            }else{
                $.error(res.msg);
            }
        })
    },
    
}))